package com.huopaolan.yohuoshop.Mvp.View.Activity;

import android.graphics.Color;
import android.support.design.widget.TabLayout;
import android.support.design.widget.TabLayout.OnTabSelectedListener;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.RadioButton;

import com.huopaolan.lib_core.Base.BaseActivity;
import com.huopaolan.yohuoshop.Mvp.View.Fragment.ClassifyFragment;
import com.huopaolan.yohuoshop.Mvp.View.Fragment.CommunityFragment;
import com.huopaolan.yohuoshop.Mvp.View.Fragment.HomeFragment;
import com.huopaolan.yohuoshop.Mvp.View.Fragment.MyFragment;
import com.huopaolan.yohuoshop.Mvp.View.Fragment.ShoesFragment;
import com.huopaolan.yohuoshop.R;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;

import pl.droidsonroids.gif.GifImageView;

public class MainActivity extends BaseActivity implements OnClickListener, OnTabSelectedListener {
    private Fragment currentPosition;
    private SlidingMenu slidingMenu;
    private RadioButton btn_home, btn_catergpry, btn_see, btn_my;
    private GifImageView gifImageView;
    private HomeFragment homeFragment;
    private ClassifyFragment classifyFragment;
    private ShoesFragment shoesFragment;
    private CommunityFragment communityFragment;
    private TabLayout tabLayout;
    private MyFragment myFragment;

    @Override
    public int layoutID() {
        return R.layout.activity_main;
    }

    @Override
    public void initView() {
        btn_home = findViewById(R.id.btn_home_page);
        btn_catergpry = findViewById(R.id.btn_home_category);
        btn_see = findViewById(R.id.btn_home_see);
        btn_my = findViewById(R.id.btn_home_my);
        gifImageView = findViewById(R.id.giv_home_ufo);
        gifImageView.setOnClickListener(this);
        btn_home.setOnClickListener(this);
        btn_catergpry.setOnClickListener(this);
        btn_see.setOnClickListener(this);
        btn_my.setOnClickListener(this);
        homeFragment = new HomeFragment();
        classifyFragment = new ClassifyFragment();
        shoesFragment = new ShoesFragment();
        communityFragment = new CommunityFragment();
        myFragment = new MyFragment();

        initMenu();
    }

    private void initMenu() {
        //创建对象
        slidingMenu = new SlidingMenu(this);
        //设置属性
        slidingMenu.setMode(SlidingMenu.LEFT);
        slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
        slidingMenu.setBehindOffset(200);
//        slidingMenu.setSecondaryShadowDrawable();
        View menu = LayoutInflater.from(MainActivity.this).inflate(R.layout.slidingmenu_layout, null);
        slidingMenu.setMenu(menu);
        slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
        tabLayout = menu.findViewById(R.id.home_tab);
        tabLayout.addTab(tabLayout.newTab().setText("MEN"));
        tabLayout.addTab(tabLayout.newTab().setText("WOMEN"));
        tabLayout.setOnTabSelectedListener(this);
        FragmentSelect(homeFragment);
    }

    private void FragmentSelect(Fragment fragment) {
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = manager.beginTransaction();
        if (currentPosition != fragment) {
            if (currentPosition != null && currentPosition.isAdded()) {
                fragmentTransaction.hide(currentPosition);
            }
            if (!fragment.isAdded()) {
                fragmentTransaction.add(R.id.fl_home, fragment, "");
                fragmentTransaction.show(fragment);
                fragmentTransaction.commit();
            } else {
                fragmentTransaction.show(fragment);
                fragmentTransaction.commit();
            }
            currentPosition = fragment;
        }
    }

    @Override
    public void initData() {

    }

    @Override
    public void setUpDagger() {

    }

    @Override
    public void showDialog() {

    }

    @Override
    public void hideDialog() {

    }

    @Override
    protected void onStart() {
        Window window = getWindow();
        window.setStatusBarColor(Color.BLACK);
        super.onStart();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_home_page:
                break;
            case R.id.btn_home_category:
                break;
            case R.id.btn_home_see:
                break;
            case R.id.btn_home_my:
                break;
        }
    }

    @Override
    public void onTabSelected(TabLayout.Tab tab) {

    }

    @Override
    public void onTabUnselected(TabLayout.Tab tab) {

    }

    @Override
    public void onTabReselected(TabLayout.Tab tab) {

    }
}
